
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>JNI · Aivin开发笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Aivin">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-versions-select/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-local-video/video-js.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../styles/website.css">
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="JNI基础.html" />
    
    
    <link rel="prev" href="../QT/QT基础.html" />
    

    
        <link rel="shortcut icon" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    项目说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../linux/linux基础.html">
            
                <a href="../linux/linux基础.html">
            
                    
                    linux
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../linux/linux基础.html">
            
                <a href="../linux/linux基础.html">
            
                    
                    linux基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../linux/android底层开发.html">
            
                <a href="../linux/android底层开发.html">
            
                    
                    android底层开发
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../c语言/c基础.html">
            
                <a href="../c语言/c基础.html">
            
                    
                    c
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../c语言/c基础.html">
            
                <a href="../c语言/c基础.html">
            
                    
                    c基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../c++/c++基础.html">
            
                <a href="../c++/c++基础.html">
            
                    
                    c++
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../c++/c++基础.html">
            
                <a href="../c++/c++基础.html">
            
                    
                    c++基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../QT/QT基础.html">
            
                <a href="../QT/QT基础.html">
            
                    
                    QT
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../QT/QT基础.html">
            
                <a href="../QT/QT基础.html">
            
                    
                    QT基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter active" data-level="1.6" data-path="JNI基础.html">
            
                <a href="JNI基础.html">
            
                    
                    JNI
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.6.1" data-path="JNI基础.html">
            
                <a href="JNI基础.html">
            
                    
                    JNI基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="JNI例子.html">
            
                <a href="JNI例子.html">
            
                    
                    JNI例子
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../SDL/SDL基础.html">
            
                <a href="../SDL/SDL基础.html">
            
                    
                    SDL
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../SDL/SDL基础.html">
            
                <a href="../SDL/SDL基础.html">
            
                    
                    SDL基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../ffmpeg/ffmpeg基础.html">
            
                <a href="../ffmpeg/ffmpeg基础.html">
            
                    
                    ffmpeg
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../ffmpeg/ffmpeg基础.html">
            
                <a href="../ffmpeg/ffmpeg基础.html">
            
                    
                    ffmpeg基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../ffmpeg/ffmpeg示例代码.html">
            
                <a href="../ffmpeg/ffmpeg示例代码.html">
            
                    
                    ffmpeg示例代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../ffmpeg/ffmpeg软解rtsp简单直播.html">
            
                <a href="../ffmpeg/ffmpeg软解rtsp简单直播.html">
            
                    
                    ffmpeg软解rtsp简单直播
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../ffmpeg/rtsp服务器.html">
            
                <a href="../ffmpeg/rtsp服务器.html">
            
                    
                    rtsp服务器Windows
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../opencv/opencv模块.html">
            
                <a href="../opencv/opencv模块.html">
            
                    
                    opencv模块
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../opencv/opencv.html">
            
                <a href="../opencv/opencv.html">
            
                    
                    opencv
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../openSLES/openSLES基础.html">
            
                <a href="../openSLES/openSLES基础.html">
            
                    
                    openSLES
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../openSLES/openSLES基础.html">
            
                <a href="../openSLES/openSLES基础.html">
            
                    
                    openSLES基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../SoundTouch/移植SoundTouch.html">
            
                <a href="../SoundTouch/移植SoundTouch.html">
            
                    
                    SoundTouch
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../SoundTouch/移植SoundTouch.html">
            
                <a href="../SoundTouch/移植SoundTouch.html">
            
                    
                    移植SoundTouch
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../SoundTouch/实现音频变速和变调.html">
            
                <a href="../SoundTouch/实现音频变速和变调.html">
            
                    
                    实现音频变速和变调
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../openGLES/openGLES基础.html">
            
                <a href="../openGLES/openGLES基础.html">
            
                    
                    openGLES模块
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../openGLES/openGLES基础.html">
            
                <a href="../openGLES/openGLES基础.html">
            
                    
                    openGLES基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../openGLES/GLSL基础.html">
            
                <a href="../openGLES/GLSL基础.html">
            
                    
                    GLSL基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../openGLES/openglES示例.html">
            
                <a href="../openGLES/openglES示例.html">
            
                    
                    openglES示例
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../视频相关/音视频基础.html">
            
                <a href="../视频相关/音视频基础.html">
            
                    
                    音视频术语-文件格式-协议
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../视频相关/音视频基础.html">
            
                <a href="../视频相关/音视频基础.html">
            
                    
                    音视频基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../视频相关/RTSP.html">
            
                <a href="../视频相关/RTSP.html">
            
                    
                    RTSP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="../视频相关/RTP.html">
            
                <a href="../视频相关/RTP.html">
            
                    
                    RTP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.4" data-path="../视频相关/RTCP.html">
            
                <a href="../视频相关/RTCP.html">
            
                    
                    RTCP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.5" data-path="../视频相关/H264.html">
            
                <a href="../视频相关/H264.html">
            
                    
                    H264
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.6" data-path="../视频相关/YUV.html">
            
                <a href="../视频相关/YUV.html">
            
                    
                    YUV
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.7" data-path="../视频相关/SurfaceView.html">
            
                <a href="../视频相关/SurfaceView.html">
            
                    
                    SurfaceView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.8" data-path="../视频相关/RTMP.html">
            
                <a href="../视频相关/RTMP.html">
            
                    
                    RTMP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.9" data-path="../视频相关/AAC详解.html">
            
                <a href="../视频相关/AAC详解.html">
            
                    
                    AAC详解
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../音视频相关代码/音视频相关代码.html">
            
                <a href="../音视频相关代码/音视频相关代码.html">
            
                    
                    音视频相关代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../ndk/NDK编译基础.html">
            
                <a href="../ndk/NDK编译基础.html">
            
                    
                    NDK工程编译
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../ndk/NDK编译基础.html">
            
                <a href="../ndk/NDK编译基础.html">
            
                    
                    NDK编译基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2" data-path="../ndk/cmake方式.html">
            
                <a href="../ndk/cmake方式.html">
            
                    
                    cmake
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3" data-path="../ndk/Android.mk模板.html">
            
                <a href="../ndk/Android.mk模板.html">
            
                    
                    Android.mk
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4" data-path="../ndk/Application.mk模板.html">
            
                <a href="../ndk/Application.mk模板.html">
            
                    
                    Application.mk
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >JNI</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#jni&#x57FA;&#x7840;"><b>1. </b>jni&#x57FA;&#x7840;</a></li><ul><li><span class="title-icon "></span><a href="#jni-&#x4F7F;&#x7528;&#x573A;&#x666F;"><b>1.1. </b>JNI &#x4F7F;&#x7528;&#x573A;&#x666F;</a></li><li><span class="title-icon "></span><a href="#jni&#x8BED;&#x6CD5;"><b>1.2. </b>JNI&#x8BED;&#x6CD5;</a></li><ul><li><span class="title-icon "></span><a href="#jnienv"><b>1.2.1. </b>JNIEnv</a></li></ul><li><span class="title-icon "></span><a href="#jni&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;"><b>1.3. </b>JNI&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;</a></li><li><span class="title-icon "></span><a href="#&#x5B57;&#x7B26;&#x4E32;"><b>1.4. </b>&#x5B57;&#x7B26;&#x4E32;</a></li><li><span class="title-icon "></span><a href="#jni&#x7B7E;&#x540D;"><b>1.5. </b>JNI&#x7B7E;&#x540D;</a></li><ul><li><span class="title-icon "></span><a href="#&#x57FA;&#x672C;&#x6570;&#x636E;&#x7B7E;&#x540D;&#x7684;&#x89C4;&#x5219;"><b>1.5.1. </b>&#x57FA;&#x672C;&#x6570;&#x636E;&#x7B7E;&#x540D;&#x7684;&#x89C4;&#x5219;</a></li><li><span class="title-icon "></span><a href="#&#x7B7E;&#x540D;&#x8BE6;&#x89E3;"><b>1.5.2. </b>&#x7B7E;&#x540D;&#x8BE6;&#x89E3;</a></li></ul><li><span class="title-icon "></span><a href="#&#x5F15;&#x7528;&#x7C7B;&#x578B;"><b>1.6. </b>&#x5F15;&#x7528;&#x7C7B;&#x578B;</a></li><li><span class="title-icon "></span><a href="#java-&#x548C;-c-&#x51FD;&#x6570;&#x7684;&#x6620;&#x5C04;&#x8868;"><b>1.7. </b>Java &#x548C; C &#x51FD;&#x6570;&#x7684;&#x6620;&#x5C04;&#x8868;</a></li><li><span class="title-icon "></span><a href="#&#x5E38;&#x7528;&#x51FD;&#x6570;"><b>1.8. </b>&#x5E38;&#x7528;&#x51FD;&#x6570;</a></li><ul><li><span class="title-icon "></span><a href="#jnionload"><b>1.8.1. </b>JNI_OnLoad(...)</a></li></ul><li><span class="title-icon "></span><a href="#&#x6253;&#x5370;&#x65E5;&#x5FD7;"><b>1.9. </b>&#x6253;&#x5370;&#x65E5;&#x5FD7;</a></li><li><span class="title-icon "></span><a href="#&#x5F02;&#x5E38;&#x5B9A;&#x4F4D;"><b>1.10. </b>&#x5F02;&#x5E38;&#x5B9A;&#x4F4D;</a></li><li><span class="title-icon "></span><a href="#&#x7F13;&#x5B58;&#x7B56;&#x7565;"><b>1.11. </b>&#x7F13;&#x5B58;&#x7B56;&#x7565;</a></li><li><span class="title-icon "></span><a href="#java&#x8C03;&#x7528;native"><b>1.12. </b>java&#x8C03;&#x7528;native</a></li><li><span class="title-icon "></span><a href="#native-&#x8C03;&#x7528;-java"><b>1.13. </b>native &#x8C03;&#x7528; java</a></li><ul><li><span class="title-icon "></span><a href="#c&#x4E3B;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;java&#x65B9;&#x6CD5;"><b>1.13.1. </b>C++&#x4E3B;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;Java&#x65B9;&#x6CD5;</a></li><li><span class="title-icon "></span><a href="#c&#x5B50;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;java&#x65B9;&#x6CD5;"><b>1.13.2. </b>C++&#x5B50;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;Java&#x65B9;&#x6CD5;</a></li></ul><li><span class="title-icon "></span><a href="#posix&#x7EBF;&#x7A0B;"><b>1.14. </b>POSIX&#x7EBF;&#x7A0B;</a></li><ul><li><span class="title-icon "></span><a href="#posix-&#x4F7F;&#x7528;"><b>1.14.1. </b>POSIX &#x4F7F;&#x7528;</a></li><li><span class="title-icon "></span><a href="#posix-&#x5E38;&#x7528;&#x65B9;&#x6CD5;"><b>1.14.2. </b>POSIX &#x5E38;&#x7528;&#x65B9;&#x6CD5;</a></li></ul><li><span class="title-icon "></span><a href="#java&#x4E0E;native&#x5171;&#x4EAB;&#x5185;&#x5B58;"><b>1.15. </b>java&#x4E0E;native&#x5171;&#x4EAB;&#x5185;&#x5B58;</a></li><li><span class="title-icon "></span><a href="#&#x5176;&#x4ED6;"><b>1.16. </b>&#x5176;&#x4ED6;</a></li></ul></ul></div><a href="#jni&#x57FA;&#x7840;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="jni&#x57FA;&#x7840;"><a name="jni&#x57FA;&#x7840;" class="anchor-navigation-ex-anchor" href="#jni&#x57FA;&#x7840;"><i class="fa fa-link" aria-hidden="true"></i></a>1. jni&#x57FA;&#x7840;</h1>
<p>&#x57FA;&#x4E8E; Androidstudio &#x3001;cmake &#x3001; c/c++  &#x3002;&#x6CE8;&#x610F;&#xFF1A;jni&#x5C42;&#x53BB;&#x8BFB;&#x53D6;SD&#x5361;&#x7684;&#x6587;&#x4EF6;&#xFF0C;&#x9700;&#x8981;&#x5728;AndroidManifest.xml&#x914D;&#x7F6E;&#x6743;&#x9650;&#x3002; </p>
<h2 id="jni-&#x4F7F;&#x7528;&#x573A;&#x666F;"><a name="jni-&#x4F7F;&#x7528;&#x573A;&#x666F;" class="anchor-navigation-ex-anchor" href="#jni-&#x4F7F;&#x7528;&#x573A;&#x666F;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. JNI &#x4F7F;&#x7528;&#x573A;&#x666F;</h2>
<pre><code class="lang-xml">1&#x3001;&#x63D0;&#x9AD8;&#x4EE3;&#x7801;&#x5B89;&#x5168;&#x6027;&#x3002;&#x56E0;&#x4E3A;.so&#x6587;&#x4EF6;&#x53CD;&#x7F16;&#x8BD1;&#x56F0;&#x96BE;&#x3002;&#xFF08;&#x52A0;&#x5BC6;&#x4E00;&#x4E9B;&#x7B97;&#x6CD5;&#x7B49;&#xFF09;
2&#x3001;&#x65B9;&#x4FBF;&#x4F7F;&#x7528;&#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x7684;c/c++&#x5E93;&#x3002;&#x53EF;&#x4EE5;&#x52A0;&#x8F7D; .dll &#x548C; .so &#x683C;&#x5F0F;&#x7684;&#x52A8;&#x6001;&#x5E93;&#x3002;
3&#x3001;&#x63D0;&#x9AD8;&#x67D0;&#x4E9B;&#x7279;&#x5B9A;&#x60C5;&#x51B5;&#x4E0B;&#x7684;&#x6267;&#x884C;&#x6548;&#x7387;&#x3002;&#xFF08;c/c++&#x7684;&#x6548;&#x7387;&#x6BD4;java&#x9AD8;&#x3002;&#x4E0D;&#x8FC7;&#x5E76;&#x4E0D;&#x80FD;&#x660E;&#x663E;&#x63D0;&#x5347;android&#x7A0B;&#x5E8F;&#x7684;&#x6027;&#x80FD;&#xFF09;
</code></pre>
<h2 id="jni&#x8BED;&#x6CD5;"><a name="jni&#x8BED;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#jni&#x8BED;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. JNI&#x8BED;&#x6CD5;</h2>
<pre><code class="lang-xml">#ifdef __cplusplus
extern &quot;C&quot;
#endif
// &#x5982;&#x679C;&#x662F;c++&#x4EE3;&#x7801;&#xFF0C;&#x4E5F;&#x7EDF;&#x4E00;&#x7528;c&#x7684;&#x8BED;&#x6CD5;&#x53BB;&#x7F16;&#x8BD1;&#x3002;
#ifdef __cplusplus
extern &quot;}&quot;
#endif


extern &quot;C&quot; JNIEXPORT void JNICALL
Java_com_xxx_nPlay(JNIEnv *env, jobject instance, jstring url_) { 
 ...
}

extern &quot;C&quot;
JNIEXPORT void JNICALL
Java_com_kgdwbb_jnistudy_MainActivity_helloJNI(JNIEnv* env, jobject thiz,jstring msg) {
    //do something
}
extern &quot;C&quot;  // &#x4EE3;&#x7801;&#x662F;&#x7528;C++&#x8BED;&#x8A00;&#x5199;&#x7684;&#x5C31;&#x9700;&#x8981;&#x7528;&#x8FD9;&#x4E2A;&#xFF0C;  C&#x8BED;&#x8A00;&#x7F16;&#x5199;&#x5219;&#x4E0D;&#x9700;&#x8981;&#x3002;
JNIEXPORT   // &#x6807;&#x8BB0;&#x4E3A;&#x8BE5;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x88AB;&#x5916;&#x90E8;&#x8C03;&#x7528;&#xFF0C;&#x7C7B;&#x4F3C;Java&#x7684;public&#x51FD;&#x6570;&#x548C;private&#x51FD;&#x6570;&#x7684;&#x533A;&#x522B;&#x3002;
JNICALL     // &#x8BF4;&#x660E;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x662F;&#x4E00;&#x4E2A;JNI&#x51FD;&#x6570;&#xFF0C;&#x7528;&#x6765;&#x548C;&#x666E;&#x901A;&#x7684;C/C++&#x51FD;&#x6570;&#x8FDB;&#x884C;&#x533A;&#x522B;&#x3002;
</code></pre>
<h3 id="jnienv"><a name="jnienv" class="anchor-navigation-ex-anchor" href="#jnienv"><i class="fa fa-link" aria-hidden="true"></i></a>1.2.1. JNIEnv</h3>
<pre><code class="lang-xml">JNIEnv&#x662F; JavaVM &#x5728;&#x7EBF;&#x7A0B;&#x4E2D;&#x7684;&#x4EE3;&#x8868;, &#x6BCF;&#x4E2A;&#x7EBF;&#x7A0B;&#x90FD;&#x6709;&#x4E00;&#x4E2A;, JNI &#x4E2D;&#x53EF;&#x80FD;&#x6709;&#x5F88;&#x591A;&#x4E2A; JNIEnv;
&#x6BCF;&#x4E2A;JNIEnv &#x90FD;&#x662F;&#x7EBF;&#x7A0B;&#x4E13;&#x6709;&#x7684;, &#x5176;&#x5B83;&#x7EBF;&#x7A0B;&#x4E0D;&#x80FD;&#x4F7F;&#x7528;&#x672C;&#x7EBF;&#x7A0B;&#x4E2D;&#x7684; JNIEnv, &#x7EBF;&#x7A0B; A &#x4E0D;&#x80FD;&#x8C03;&#x7528; &#x7EBF;&#x7A0B; B &#x7684; JNIEnv;
&#x4F46;&#x662F;&#xFF0C;&#x4E00;&#x4E2A;&#x672C;&#x5730;&#x65B9;&#x6CD5;&#x53EF;&#x88AB;&#x4E0D;&#x540C;&#x7684; Java &#x7EBF;&#x7A0B;&#x6240;&#x8C03;&#x7528;&#xFF0C;&#x56E0;&#x6B64;&#x53EF;&#x4EE5;&#x63A5;&#x53D7;&#x4E0D;&#x540C;&#x7684; JNIEnv&#x3002;

//JNIEnv &#x4F5C;&#x7528;
1&#x3001;&#x8C03;&#x7528;Java&#x51FD;&#x6570;
JNIEnv&#x4EE3;&#x8868;Java&#x8FD0;&#x884C;&#x73AF;&#x5883;,&#x53EF;&#x4EE5;&#x4F7F;&#x7528;JNIEnv&#x8C03;&#x7528;Java&#x4E2D;&#x7684;&#x4EE3;&#x7801;;

2&#x3001;&#x64CD;&#x4F5C;Java&#x5BF9;&#x8C61;
Java&#x5BF9;&#x8C61;&#x4F20;&#x5165;JNI&#x5C42;&#x5C31;&#x662F;Jobject&#x5BF9;&#x8C61;, &#x9700;&#x8981;&#x4F7F;&#x7528;JNIEnv&#x6765;&#x64CD;&#x4F5C;&#x8FD9;&#x4E2A;Java&#x5BF9;&#x8C61;;
</code></pre>
<h2 id="jni&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;"><a name="jni&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;" class="anchor-navigation-ex-anchor" href="#jni&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3. JNI&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;</h2>
<table>
<thead>
<tr>
<th>java&#x57FA;&#x672C;&#x7C7B;&#x578B;</th>
<th>JNI&#x7C7B;&#x578B;</th>
<th>bit</th>
<th>-</th>
<th>java&#x57FA;&#x672C;&#x7C7B;&#x578B;</th>
<th>JNI&#x7C7B;&#x578B;</th>
<th>bit</th>
</tr>
</thead>
<tbody>
<tr>
<td>boolean</td>
<td>jboolean</td>
<td>8</td>
<td></td>
<td>int</td>
<td>jint</td>
<td>32</td>
</tr>
<tr>
<td>byte</td>
<td>jbyte</td>
<td>8</td>
<td></td>
<td>long</td>
<td>jlong</td>
<td>64</td>
</tr>
<tr>
<td>char</td>
<td>jchar</td>
<td>16</td>
<td></td>
<td>float</td>
<td>jfloat</td>
<td>32</td>
</tr>
<tr>
<td>short</td>
<td>jshort</td>
<td>16</td>
<td></td>
<td>double</td>
<td>jdouble</td>
<td>64</td>
</tr>
<tr>
<td>void</td>
<td>void</td>
<td>&#x65E0;</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>java&#x5F15;&#x7528;&#x7C7B;&#x578B;</th>
<th>JNI&#x7C7B;&#x578B;</th>
<th>-</th>
<th>java&#x5F15;&#x7528;&#x7C7B;&#x578B;</th>
<th>JNI&#x7C7B;&#x578B; </th>
</tr>
</thead>
<tbody>
<tr>
<td>Object</td>
<td>jobject</td>
<td></td>
<td>short[ ]</td>
<td>jshortArray </td>
</tr>
<tr>
<td>Class</td>
<td>jclass</td>
<td></td>
<td>int[ ]</td>
<td>jintArray   </td>
</tr>
<tr>
<td>String</td>
<td>jstring</td>
<td></td>
<td>long[ ]</td>
<td>jlongArray  </td>
</tr>
<tr>
<td>Object[ ]</td>
<td>jobjectArray</td>
<td></td>
<td>float[ ]</td>
<td>jfloatArray </td>
</tr>
<tr>
<td>boolean[ ]</td>
<td>jbooleanArray</td>
<td></td>
<td>double[ ]</td>
<td>jdoubleArray</td>
</tr>
<tr>
<td>byte[ ]</td>
<td>jbyteArray</td>
<td></td>
<td>Throwable</td>
<td>jthrowable  </td>
</tr>
<tr>
<td>char[ ]</td>
<td>jcharArray</td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="&#x5B57;&#x7B26;&#x4E32;"><a name="&#x5B57;&#x7B26;&#x4E32;" class="anchor-navigation-ex-anchor" href="#&#x5B57;&#x7B26;&#x4E32;"><i class="fa fa-link" aria-hidden="true"></i></a>1.4. &#x5B57;&#x7B26;&#x4E32;</h2>
<pre><code class="lang-text">std::string helloCpp = &quot;Hello from C++ , aivin&quot;;
showLog(&quot;--&gt; %s&quot; ,helloCpp.c_str()) ;
</code></pre>
<h2 id="jni&#x7B7E;&#x540D;"><a name="jni&#x7B7E;&#x540D;" class="anchor-navigation-ex-anchor" href="#jni&#x7B7E;&#x540D;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5. JNI&#x7B7E;&#x540D;</h2>
<p>java&#x4E2D;&#xFF0C;&#x5BF9;&#x4E8E;&#x67D0;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x6765;&#x8BF4;&#xFF0C; &#x53EF;&#x4EE5;&#x7528;&#x8FC7;&#x65B9;&#x6CD5;&#x540D;&#x548C;&#x53C2;&#x6570; &#x5C31;&#x53EF;&#x4EE5;&#x786E;&#x5B9A;&#x552F;&#x4E00;&#x7684;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x3002;&#x5728;JNI&#x4E2D;&#xFF0C;&#x901A;&#x8FC7;&#x51FD;&#x6570;&#x540D;&#x548C; &#x7B7E;&#x540D;&#x4FE1;&#x606F; &#x53EF;&#x4EE5;&#x786E;&#x5B9A;&#x552F;&#x4E00;&#x7684;&#x65B9;&#x6CD5;&#x3002;</p>
<h3 id="&#x57FA;&#x672C;&#x6570;&#x636E;&#x7B7E;&#x540D;&#x7684;&#x89C4;&#x5219;"><a name="&#x57FA;&#x672C;&#x6570;&#x636E;&#x7B7E;&#x540D;&#x7684;&#x89C4;&#x5219;" class="anchor-navigation-ex-anchor" href="#&#x57FA;&#x672C;&#x6570;&#x636E;&#x7B7E;&#x540D;&#x7684;&#x89C4;&#x5219;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.1. &#x57FA;&#x672C;&#x6570;&#x636E;&#x7B7E;&#x540D;&#x7684;&#x89C4;&#x5219;</h3>
<table>
<thead>
<tr>
<th>java&#x7C7B;&#x578B;</th>
<th>JNI&#x7C7B;&#x578B;</th>
<th>-</th>
<th>java&#x7C7B;&#x578B;</th>
<th>JNI&#x7C7B;&#x578B;</th>
</tr>
</thead>
<tbody>
<tr>
<td>boolean</td>
<td>Z</td>
<td></td>
<td>long</td>
<td>J</td>
</tr>
<tr>
<td>byte</td>
<td>B</td>
<td></td>
<td>float</td>
<td>F</td>
</tr>
<tr>
<td>char</td>
<td>C</td>
<td></td>
<td>double</td>
<td>D</td>
</tr>
<tr>
<td>short</td>
<td>S</td>
<td></td>
<td>void</td>
<td>V</td>
</tr>
<tr>
<td>int</td>
<td>I</td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<h3 id="&#x7B7E;&#x540D;&#x8BE6;&#x89E3;"><a name="&#x7B7E;&#x540D;&#x8BE6;&#x89E3;" class="anchor-navigation-ex-anchor" href="#&#x7B7E;&#x540D;&#x8BE6;&#x89E3;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.2. &#x7B7E;&#x540D;&#x8BE6;&#x89E3;</h3>
<pre><code class="lang-xml">// &#x7C7B;&#x7684;&#x7B7E;&#x540D;&#xFF08;&#x6CE8;&#x610F;&#x672B;&#x5C3E;&#x7684;&#x5206;&#x53F7;&#xFF09;
L+&#x5305;&#x540D;+&#x7C7B;&#x540D;+&#xFF1B;
java.lang.String  -&gt;   Ljava/lang/String;

// &#x5BF9;&#x8C61;&#x7B7E;&#x540D;
&#x8DDF;&#x5B83;&#x6240;&#x5C5E;&#x7684;&#x7C7B;&#x7684;&#x7B7E;&#x540D;&#x4E00;&#x6837;&#x3002;

// &#x4E00;&#x7EF4;&#x6570;&#x7EC4;&#x7B7E;&#x540D;
&#x683C;&#x5F0F;&#xFF1A; [&#x7C7B;&#x578B;
double[ ]  -&gt;  [ D

// &#x591A;&#x7EF4;&#x6570;&#x7EC4;&#x7B7E;&#x540D;
&#x683C;&#x5F0F;&#xFF1A;  n&#x4E2A; [   + &#x7C7B;&#x578B;&#x7B7E;&#x540D;
int[ ] [ ]   -&gt;  [[I

// &#x65B9;&#x6CD5;&#x7B7E;&#x540D;   (&#x8DDF;&#x65B9;&#x6CD5;&#x540D;&#x65E0;&#x5173;)
&#x683C;&#x5F0F;&#xFF1A; &#xFF08;&#x53C2;&#x6570;&#x7C7B;&#x578B;&#x7B7E;&#x540D;&#xFF09; + &#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x7B7E;&#x540D;
boolean fun( int a , double b , int[ ] c)   -&gt;     (ID[I)Z
void fun(int i)  -&gt; (I)V
</code></pre>
<h2 id="&#x5F15;&#x7528;&#x7C7B;&#x578B;"><a name="&#x5F15;&#x7528;&#x7C7B;&#x578B;" class="anchor-navigation-ex-anchor" href="#&#x5F15;&#x7528;&#x7C7B;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>1.6. &#x5F15;&#x7528;&#x7C7B;&#x578B;</h2>
<pre><code class="lang-text">//&#x5168;&#x5C40;&#x5F15;&#x7528;
&#x5168;&#x5C40;&#x5F15;&#x7528;&#x53EF;&#x4EE5;&#x8DE8;&#x65B9;&#x6CD5;&#x3001;&#x8DE8;&#x7EBF;&#x7A0B;&#x4F7F;&#x7528;&#xFF0C;&#x76F4;&#x5230;&#x88AB;&#x663E;&#x5F0F;&#x91CA;&#x653E;&#x3002;
NewGlobalRef() //&#x65B0;&#x5EFA;&#x5168;&#x5C40;&#x53D8;&#x91CF;
DeleteGlobalRef() //&#x5220;&#x9664;&#x5168;&#x5C40;&#x5F15;&#x7528;

//&#x5C40;&#x90E8;&#x5F15;&#x7528;
&#x5C40;&#x90E8;&#x5F15;&#x7528;&#x4EC5;&#x5728;&#x521B;&#x5EFA;&#x5B83;&#x7684;native&#x51FD;&#x6570;&#x53CA;&#x8BE5;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x7684;&#x51FD;&#x6570;&#x4E2D;&#x6709;&#x6548;&#x3002;&#x5C40;&#x90E8;&#x5F15;&#x7528;&#x5C06;&#x5728;&#x8BE5;&#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x65F6;&#x88AB;&#x91CA;&#x653E;&#x3002;
DeleteLocalRef() //&#x5220;&#x9664;&#x5F15;&#x7528;

// &#x5F31;&#x5168;&#x5C40;&#x5F15;&#x7528;
&#x4E0E;&#x5168;&#x5C40;&#x5F15;&#x7528;&#x7C7B;&#x4F3C;&#xFF0C;&#x5F31;&#x5F15;&#x7528;&#x53EF;&#x4EE5;&#x8DE8;&#x65B9;&#x6CD5;&#x3001;&#x7EBF;&#x7A0B;&#x4F7F;&#x7528;&#x3002;&#x4F46;&#x5F31;&#x5F15;&#x7528;&#x4E0D;&#x4F1A;&#x963B;&#x6B62;GC&#x56DE;&#x6536;&#x5B83;&#x5F15;&#x7528;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;
&#x5B83;&#x6240;&#x5F15;&#x7528;&#x7684;&#x5BF9;&#x8C61;&#x53EF;&#x80FD;&#x662F;&#x4E0D;&#x5B58;&#x5728;&#x7684;&#x6216;&#x8005;&#x5DF2;&#x7ECF;&#x88AB;&#x56DE;&#x6536;&#x3002;&#x5728;&#x5185;&#x5B58;&#x4E0D;&#x8DB3;&#x65F6;&#x53EF;&#x80FD;&#x4F1A;&#x88AB;&#x6536;&#x56DE;&#x4E86;&#x3002;&#x4F7F;&#x7528;&#x524D;&#x5148;&#x5224;&#x65AD;&#x4E00;&#x4E0B;&#x3002;
global_weakRef_str= (jstring) env-&gt;NewWeakGlobalRef(str2);
if(! env-&gt;IsSameObject(NULL , global_weakRef_str)){
    showLog(&quot;this global_weakRef_str is usefully&quot;) ;
}
env-&gt;DeleteWeakGlobalRef(global_weakRef_str) ;
</code></pre>
<h2 id="java-&#x548C;-c-&#x51FD;&#x6570;&#x7684;&#x6620;&#x5C04;&#x8868;"><a name="java-&#x548C;-c-&#x51FD;&#x6570;&#x7684;&#x6620;&#x5C04;&#x8868;" class="anchor-navigation-ex-anchor" href="#java-&#x548C;-c-&#x51FD;&#x6570;&#x7684;&#x6620;&#x5C04;&#x8868;"><i class="fa fa-link" aria-hidden="true"></i></a>1.7. Java &#x548C; C &#x51FD;&#x6570;&#x7684;&#x6620;&#x5C04;&#x8868;</h2>
<pre><code class="lang-java"><span class="hljs-comment">// { java&#x4E2D;&#x51FD;&#x6570;&#x540D;&#x5B57; , &#x53C2;&#x6570;&#x548C;&#x8FD4;&#x56DE;&#x503C; , &#x5BF9;&#x5E94;&#x7684;c&#x51FD;&#x6570;}</span>
{
  <span class="hljs-string">&quot;setUsbLinkVideoData&quot;</span>,
  <span class="hljs-string">&quot;(Ljava/nio/ByteBuffer;I)V&quot;</span>,
    (<span class="hljs-keyword">void</span>*)com_media_ffmpeg_FFMpegPlayer_setUsbLinkVideoData
}
</code></pre>
<h2 id="&#x5E38;&#x7528;&#x51FD;&#x6570;"><a name="&#x5E38;&#x7528;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#&#x5E38;&#x7528;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>1.8. &#x5E38;&#x7528;&#x51FD;&#x6570;</h2>
<table>
<thead>
<tr>
<th>&#x51FD;&#x6570;&#x540D;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>FindClass</td>
<td></td>
</tr>
<tr>
<td>CallIntMethod</td>
<td></td>
</tr>
<tr>
<td>CallVoidMethod</td>
<td></td>
</tr>
<tr>
<td>GetStaticMethodID</td>
<td></td>
</tr>
<tr>
<td>CallStaticIntMethod</td>
<td></td>
</tr>
<tr>
<td>NewObject</td>
<td></td>
</tr>
<tr>
<td>CallStaticObjectMethod</td>
<td></td>
</tr>
<tr>
<td>NewStringUTF</td>
<td></td>
</tr>
<tr>
<td>GetStringUTFChars</td>
<td>&#x5F97;&#x5230;&#x4E00;&#x4E2A;UTF-8&#x7F16;&#x7801;&#x7684;&#x5B57;&#x7B26;&#x4E32;</td>
</tr>
<tr>
<td>GetStringChars</td>
<td>&#x5F97;&#x5230;UTF-16&#x7F16;&#x7801;&#x7684;&#x5B57;&#x7B26;&#x4E32;</td>
</tr>
<tr>
<td>ReleaseStringUTFChars</td>
<td></td>
</tr>
<tr>
<td>JNI_OnLoad</td>
<td>so&#x5E93;&#x52A0;&#x8F7D;&#x65F6;&#x8C03;&#x7528;&#x3002; <br>&#x5982;&#x679C;&#x4F60;&#x7684;*.so&#x6863;&#x6CA1;&#x6709;&#x63D0;&#x4F9B;JNI_OnLoad()&#x51FD;&#x6570;&#xFF0C;VM&#x4F1A;&#x9ED8;&#x8BA4;&#x4F7F;&#x7528;&#x6700;&#x8001;&#x7684;JNI 1.1&#x7248;&#x672C;&#x3002;</td>
</tr>
<tr>
<td>JNI_OnUnload</td>
<td>-</td>
</tr>
<tr>
<td>SetByteArrayRegion</td>
<td>&#x5C06;&#x672C;&#x5730;&#x7684;&#x6570;&#x7EC4;&#x6570;&#x636E;&#x62F7;&#x8D1D;&#x5230;&#x4E86; Java &#x7AEF;&#x7684;&#x6570;&#x7EC4;&#x4E2D;</td>
</tr>
<tr>
<td>env-&gt;ThrowNew</td>
<td>&#x629B;&#x51FA;&#x5F02;&#x5E38;&#x4FE1;&#x606F; <br> jclass exceptionClazz = env-&gt;FindClass(&quot;java/lang/RuntimeException&quot;); <br> env-&gt;ThrowNew(exceptionClazz, &quot;&#x81EA;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&quot;);</td>
</tr>
<tr>
<td>reinterpret_cast</td>
<td>&#x7C7B;&#x578B;&#x5F3A;&#x5236;&#x8F6C;&#x6362;<br>MyParcel<em> parcel = reinterpret_cast &lt;MyParcel</em>&gt;(nativePtr);</td>
</tr>
<tr>
<td>GetStaticFieldID</td>
<td></td>
</tr>
<tr>
<td>SetStaticFieldID</td>
<td></td>
</tr>
</tbody>
</table>
<pre><code class="lang-text">GetBooleanField( )  // &#x8FD4;&#x56DE;&#x5BF9;&#x8C61;&#x7684;&#x5B9E;&#x4F8B;(&#x975E;&#x9759;&#x6001;)&#x57DF;&#x7684;&#x503C;
GetByteField( )
GetCharField( )
GetShortField( )
GetIntField( )
GetLongField( )
GetFloatField( )
GetDoubleField( )

GetObjectClass( )     // &#x6839;&#x636E; &#x5BF9;&#x8C61; &#x83B7;&#x53D6;&#x7C7B;
GetMethodID( )        //  &#x6839;&#x636E;&#x540D;&#x5B57;&#x83B7;&#x53D6;Java&#x4E2D;&#x6307;&#x5B9A;&#x7C7B;&#x7684;&#x6307;&#x5B9A;&#x51FD;&#x6570;
CallVoidMethod( )     //  &#x8C03;&#x7528;&#x8FD4;&#x56DE;&#x503C;&#x4E3A;void&#x7684;Java&#x51FD;&#x6570;
CallBooleanMethod ( ) // &#x8C03;&#x7528;&#x8FD4;&#x56DE;&#x503C;&#x4E3A;boolean&#x7684;Java&#x51FD;&#x6570;
AttachCurrentThread   //&#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#x83B7;&#x53D6;JNI&#x73AF;&#x5883;
DetachCurrentThread( ) //  &#x9000;&#x51FA;&#x5F53;&#x524D;JNI&#x73AF;&#x5883;

GetBooleanArrayElements( )  // &#x83B7;&#x5F97;&#x6570;&#x7EC4;&#x6307;&#x9488;
GetByteArrayElements( )  //
GetCharArrayElements( ) 
GetShortArrayElements( ) 
GetIntArrayElements( ) 
GetLongArrayElements( ) 
GetFloatArrayElements( ) 
GetDoubleArrayElements( )
</code></pre>
<h3 id="jnionload"><a name="jnionload" class="anchor-navigation-ex-anchor" href="#jnionload"><i class="fa fa-link" aria-hidden="true"></i></a>1.8.1. JNI_OnLoad(...)</h3>
<pre><code class="lang-c">JavaVM* java_vm = <span class="hljs-literal">NULL</span>;
<span class="hljs-function">JNIEXPORT jint <span class="hljs-title">JNI_OnLoad</span><span class="hljs-params">(JavaVM* vm, <span class="hljs-keyword">void</span>* reserved)</span> </span>{
    JNIEnv *env;
    <span class="hljs-keyword">if</span> (vm-&gt;GetEnv(  (<span class="hljs-keyword">void</span>**) &amp;env,  JNI_VERSION_1_4) != JNI_OK)
    {
        <span class="hljs-keyword">return</span> JNI_ERR ;
    }
    java_vm = vm;
    <span class="hljs-keyword">return</span> JNI_VERSION_1_4;
}
</code></pre>
<h2 id="&#x6253;&#x5370;&#x65E5;&#x5FD7;"><a name="&#x6253;&#x5370;&#x65E5;&#x5FD7;" class="anchor-navigation-ex-anchor" href="#&#x6253;&#x5370;&#x65E5;&#x5FD7;"><i class="fa fa-link" aria-hidden="true"></i></a>1.9. &#x6253;&#x5370;&#x65E5;&#x5FD7;</h2>
<pre><code class="lang-c"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;android/log.h&gt;</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> LogTag <span class="hljs-string">&quot;WK_LOGER&quot;</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> LOGI(...) __android_log_print(ANDROID_LOG_INFO, LogTag ,__VA_ARGS__);</span>
</code></pre>
<h2 id="&#x5F02;&#x5E38;&#x5B9A;&#x4F4D;"><a name="&#x5F02;&#x5E38;&#x5B9A;&#x4F4D;" class="anchor-navigation-ex-anchor" href="#&#x5F02;&#x5E38;&#x5B9A;&#x4F4D;"><i class="fa fa-link" aria-hidden="true"></i></a>1.10. &#x5F02;&#x5E38;&#x5B9A;&#x4F4D;</h2>
<pre><code class="lang-text">// androidsudio JNI&#x5D29;&#x6E83; &#x62A5;&#x9519;&#x5B9A;&#x4F4D;&#xFF1A;
xxx \app\build\intermediates\cmake\debug\obj 
&#x8BF7;&#x8FDB;&#x5165;&#x6B63;&#x786E;&#x7684;&#x76EE;&#x5F55; , &#x8BE5;&#x76EE;&#x5F55;&#x4E0B;&#x6709;&#x5404;&#x79CD;&#x67B6;&#x6784;&#x7C7B;&#x578B;&#x7684;&#x6587;&#x4EF6;&#x5939;&#xFF0C; arm64-v8a&#x3001;armeabi-v7a&#x3001;x86_64&#x7B49;&#x3002;
&#x627E;&#x5230;&#x6709;XX.so &#x7684;&#x6587;&#x4EF6;&#x5939;&#x3002;&#x4F8B;&#x5982;&#x6211;&#x7684;&#x5C31;&#x662F; arm64-v8a &#x91CC;&#x9762;&#x6709;so&#x3002;
&#x8F93;&#x5165;&#x547D;&#x4EE4;&#xFF1A;adb shell logcat | ndk-stack -sym arm64-v8a &#x3002;
&#x4F1A;&#x63D0;&#x793A;&#x662F;&#x5177;&#x4F53;&#x54EA;&#x4E00;&#x884C;&#x4EE3;&#x7801;&#x62A5;&#x9519;&#xFF0C;&#x4E0D;&#x8FC7;&#x4ECD;&#x7136;&#x4E0D;&#x80FD;&#x50CF;Java&#x4EE3;&#x7801;&#x70B9;&#x51FB;&#x5C31;&#x4F1A;&#x8DF3;&#x8F6C;&#x7684;&#x3002;

//cmake&#x7F16;&#x8BD1;&#x9519;&#x8BEF;&#x5B9A;&#x4F4D;&#xFF1A;
&#x5F53;CMakeLists.txt &#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x914D;&#x7F6E;&#x9519;&#x8BEF;&#x65F6;&#xFF0C;&#x4F1A;&#x63D0;&#x793A;&#x7F16;&#x8BD1;&#x4E0D;&#x8FC7;&#xFF0C;&#x9519;&#x8BEF;&#x5B9A;&#x4F4D;&#x65B9;&#x6CD5;&#x3002;
CMake&#x7684;&#x9519;&#x8BEF;&#x8F93;&#x51FA;&#x4E0D;&#x5728;console&#x7A97;&#x53E3;&#x4E2D;&#xFF0C;&#x800C;&#x662F;&#x5728; &#x672C;&#x5DE5;&#x7A0B;&#x7684; cmake_server_log.txt&#x6587;&#x4EF6;&#x4E2D;&#x3002;
&#x6253;&#x5F00;&#x8BE5;&#x6587;&#x4EF6;&#x641C;&#x7D22;error&#x5173;&#x952E;&#x5B57;&#xFF0C;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x5177;&#x4F53;&#x7684;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&#x3002;
</code></pre>
<h2 id="&#x7F13;&#x5B58;&#x7B56;&#x7565;"><a name="&#x7F13;&#x5B58;&#x7B56;&#x7565;" class="anchor-navigation-ex-anchor" href="#&#x7F13;&#x5B58;&#x7B56;&#x7565;"><i class="fa fa-link" aria-hidden="true"></i></a>1.11. &#x7F13;&#x5B58;&#x7B56;&#x7565;</h2>
<p>&#x76F4;&#x63A5;&#x7528;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x4E5F;&#x53EF;&#x4EE5;&#xFF08;&#x4F46;&#x662F;&#x53EF;&#x80FD;&#x4F1A;&#x88AB;&#x5176;&#x4ED6;&#x7C7B;&#x7684;&#x7A0B;&#x5E8F;&#x4FEE;&#x6539;&#xFF09;&#xFF0C;&#x6240;&#x4EE5;&#x5EFA;&#x8BAE;&#x7528;&#x9759;&#x6001;static&#x8F83;&#x5B89;&#x5168;&#x3002;</p>
<pre><code class="lang-xml">Java_com_xxx_staticLocalCache(JNIEnv *env, jclass jclz, jstring name) { 
    static jfieldID j_fid = NULL;  //&#x5C40;&#x90E8;&#x7F13;&#x5B58;
    if (j_fid == NULL) {
        j_fid = (*env)-&gt;GetStaticFieldID(env, jclz, &quot;name&quot;, &quot;Ljava/lang/String;&quot;)
    }  
}

static jfieldID j_fid = NULL;// &#x5168;&#x5C40;&#x7F13;&#x5B58;
Java_com_xxx_initStaticCache  (JNIEnv *env, jclass jclz){
    j_fid = (*env)-&gt;GetStaticFieldID(env, jclz, &quot;name&quot;, &quot;Ljava/lang/String;&quot;);
}
// &#x8FD9;&#x4E5F;&#x53EB;&#x7F13;&#x5B58;&#xFF1F;&#x4E71;&#x4E03;&#x516B;&#x7CDF;&#x3002;
</code></pre>
<h2 id="java&#x8C03;&#x7528;native"><a name="java&#x8C03;&#x7528;native" class="anchor-navigation-ex-anchor" href="#java&#x8C03;&#x7528;native"><i class="fa fa-link" aria-hidden="true"></i></a>1.12. java&#x8C03;&#x7528;native</h2>
<p>&#x6CE8;&#x610F;&#x6587;&#x4EF6;&#x5939;&#x8DEF;&#x5F84;&#x8981;&#x548C;native&#x4E2D;&#x7684;&#x7B7E;&#x540D;&#x4E00;&#x6837;</p>
<pre><code class="lang-xml">static {
    System.loadLibrary(&quot;music-player&quot;);
}
private native void nPlay(String url);
</code></pre>
<h2 id="native-&#x8C03;&#x7528;-java"><a name="native-&#x8C03;&#x7528;-java" class="anchor-navigation-ex-anchor" href="#native-&#x8C03;&#x7528;-java"><i class="fa fa-link" aria-hidden="true"></i></a>1.13. native &#x8C03;&#x7528; java</h2>
<h3 id="c&#x4E3B;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;java&#x65B9;&#x6CD5;"><a name="c&#x4E3B;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;java&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#c&#x4E3B;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;java&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.13.1. C++&#x4E3B;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;Java&#x65B9;&#x6CD5;</h3>
<pre><code class="lang-c++"><span class="hljs-number">1</span>&#x3001;&#x6839;&#x636E;jobject&#x83B7;&#x53D6;jclass
 jclass jlz = env-&gt;GetObjectClass(instance);<span class="hljs-comment">//jobject instance</span>
<span class="hljs-number">2</span>&#x3001;&#x83B7;&#x53D6; jmethodID
jmethodID jmid_error= jniEnv-&gt;GetMethodID(jlz, <span class="hljs-string">&quot;onError&quot;</span>, <span class="hljs-string">&quot;(ILjava/lang/String;)V&quot;</span>);
<span class="hljs-number">3</span>&#x3001;&#x8C03;&#x7528;&#x65B9;&#x6CD5;
jniEnv-&gt;CallVoidMethod(jobj, jmid_error, code, jmsg);<span class="hljs-comment">// jobject,jmethodID , &#x53C2;&#x6570;...</span>
</code></pre>
<h3 id="c&#x5B50;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;java&#x65B9;&#x6CD5;"><a name="c&#x5B50;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;java&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#c&#x5B50;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;java&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.13.2. C++&#x5B50;&#x7EBF;&#x7A0B;&#x8C03;&#x7528;Java&#x65B9;&#x6CD5;</h3>
<pre><code class="lang-c++">JniEnv&#x662F;&#x7EBF;&#x7A0B;&#x76F8;&#x5173;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x5B50;&#x7EBF;&#x7A0B;&#x4E2D;&#x4E0D;&#x80FD;&#x4F7F;&#x7528;&#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x7684;JniEnv&#xFF1B;
JVM&#x662F;&#x8FDB;&#x7A0B;&#x76F8;&#x5173;&#x7684;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;JVM&#x6765;&#x83B7;&#x53D6;&#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#x7684;JniEnv&#xFF0C;&#x7136;&#x540E;&#x624D;&#x80FD;&#x8C03;&#x7528;Java&#x7684;&#x65B9;&#x6CD5;&#x3002;

JNIEnv *jniEnv;
<span class="hljs-keyword">if</span> (javaVM-&gt;AttachCurrentThread(&amp;jniEnv, <span class="hljs-number">0</span>) != JNI_OK)
{
    <span class="hljs-keyword">return</span>;
}
<span class="hljs-comment">// &#x5982;&#x679C;&#x83B7;&#x53D6;&#x6210;&#x529F;&#xFF0C;AttachCurrentThread &#x5C31;&#x4F1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5C5E;&#x4E8E;&#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#x7684;JNIEnv&#x6307;&#x9488;&#x3002;</span>
jniEnv-&gt;CallVoidMethod(...);
<span class="hljs-comment">//&#x6267;&#x884C;&#x76F8;&#x5173;&#x64CD;&#x4F5C;...</span>
javaVM-&gt;DetachCurrentThread();
</code></pre>
<h2 id="posix&#x7EBF;&#x7A0B;"><a name="posix&#x7EBF;&#x7A0B;" class="anchor-navigation-ex-anchor" href="#posix&#x7EBF;&#x7A0B;"><i class="fa fa-link" aria-hidden="true"></i></a>1.14. POSIX&#x7EBF;&#x7A0B;</h2>
<p>Android NDK&#x7684;&#x7EBF;&#x7A0B;&#x662F;&#x901A;&#x8FC7;POSIX&#x6807;&#x51C6;&#x5B9E;&#x73B0;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x4E5F;&#x53EB;POSIX&#x7EBF;&#x7A0B;&#x3002;</p>
<h3 id="posix-&#x4F7F;&#x7528;"><a name="posix-&#x4F7F;&#x7528;" class="anchor-navigation-ex-anchor" href="#posix-&#x4F7F;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a>1.14.1. POSIX &#x4F7F;&#x7528;</h3>
<pre><code class="lang-c"><span class="hljs-comment">//&#x5934;&#x6587;&#x4EF6;</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;pthread.h&gt;</span></span>
<span class="hljs-comment">// &#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x9501;&#x5BF9;&#x8C61;</span>
<span class="hljs-keyword">pthread_mutex_t</span> mutex;
<span class="hljs-comment">// &#x7528;&#x6765;&#x7533;&#x660E;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#x5BF9;&#x8C61;</span>
<span class="hljs-keyword">pthread_t</span> thread
<span class="hljs-comment">//&#x521B;&#x5EFA;&#x7EBF;&#x7A0B;&#x6761;&#x4EF6;&#x5BF9;&#x8C61;</span>
<span class="hljs-keyword">pthread_cond_t</span> cond; 
<span class="hljs-keyword">pthread_attr_t</span>&#xFF1A;&#x7EBF;&#x7A0B;&#x5C5E;&#x6027;
Thread-local storage&#xFF08;&#x6216;&#x8005;&#x4EE5;Pthreads&#x672F;&#x8BED;&#xFF0C;&#x79F0;&#x4F5C;&#x7EBF;&#x7A0B;&#x7279;&#x6709;&#x6570;&#x636E;&#xFF09;&#xFF1A;
</code></pre>
<h3 id="posix-&#x5E38;&#x7528;&#x65B9;&#x6CD5;"><a name="posix-&#x5E38;&#x7528;&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#posix-&#x5E38;&#x7528;&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.14.2. POSIX &#x5E38;&#x7528;&#x65B9;&#x6CD5;</h3>
<table>
<thead>
<tr>
<th>&#x5E38;&#x7528;&#x65B9;&#x6CD5;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>pthread_create(...)</td>
<td>&#x521B;&#x5EFA;&#x7EBF;&#x7A0B;. <br>pthread_create(&amp;playThreadT, NULL, threadPlay, this);<br>&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x8FD0;&#x884C;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x3002;</td>
</tr>
<tr>
<td>pthread_detach()</td>
<td>&#x5373;&#x4E3B;&#x7EBF;&#x7A0B;&#x4E0E;&#x5B50;&#x7EBF;&#x7A0B;&#x5206;&#x79BB;&#xFF0C;&#x5B50;&#x7EBF;&#x7A0B;&#x7ED3;&#x675F;&#x540E;&#xFF0C;&#x5B50;&#x7EBF;&#x7A0B;&#x8D44;&#x6E90;&#x81EA;&#x52A8;&#x56DE;&#x6536;</td>
</tr>
<tr>
<td>pthread_exit()</td>
<td>&#x7EC8;&#x6B62;&#x5F53;&#x524D;&#x7EBF;&#x7A0B;</td>
</tr>
<tr>
<td>pthread_join()</td>
<td>&#x963B;&#x585E;&#x5F53;&#x524D;&#x7684;&#x7EBF;&#x7A0B;&#xFF0C;&#x76F4;&#x5230;&#x53E6;&#x5916;&#x4E00;&#x4E2A;&#x7EBF;&#x7A0B;&#x8FD0;&#x884C;&#x7ED3;&#x675F;</td>
</tr>
<tr>
<td>pthread_attr_init()</td>
<td>&#x521D;&#x59CB;&#x5316;&#x7EBF;&#x7A0B;&#x7684;&#x5C5E;&#x6027;</td>
</tr>
<tr>
<td>pthread_attr_setdetachstate()</td>
<td>&#x51B3;&#x5B9A;&#x8FD9;&#x4E2A;&#x7EBF;&#x7A0B;&#x5728;&#x7EC8;&#x6B62;&#x65F6;&#x662F;&#x5426;&#x53EF;&#x4EE5;&#x88AB;&#x7ED3;&#x5408;</td>
</tr>
<tr>
<td>pthread_attr_getdetachstate()</td>
<td>&#x83B7;&#x53D6;&#x8131;&#x79BB;&#x72B6;&#x6001;&#x7684;&#x5C5E;&#x6027;</td>
</tr>
<tr>
<td>pthread_attr_destroy()</td>
<td>&#x5220;&#x9664;&#x7EBF;&#x7A0B;&#x7684;&#x5C5E;&#x6027;</td>
</tr>
<tr>
<td>pthread_kill()</td>
<td>&#x5411;&#x7EBF;&#x7A0B;&#x53D1;&#x9001;&#x4E00;&#x4E2A;&#x4FE1;&#x53F7;</td>
</tr>
<tr>
<td>pthread_mutex_init(...)</td>
<td>&#x521D;&#x59CB;&#x5316;&#x4E92;&#x65A5;&#x9501;</td>
</tr>
<tr>
<td>pthread_mutex_destroy(...)</td>
<td>&#x5220;&#x9664;&#x4E92;&#x65A5;&#x9501;</td>
</tr>
<tr>
<td>pthread_mutex_lock(...)</td>
<td>&#x5360;&#x6709;&#x4E92;&#x65A5;&#x9501;&#xFF08;&#x963B;&#x585E;&#x64CD;&#x4F5C;&#xFF09;</td>
</tr>
<tr>
<td>pthread_mutex_trylock()</td>
<td>&#x8BD5;&#x56FE;&#x5360;&#x6709;&#x4E92;&#x65A5;&#x9501;</td>
</tr>
<tr>
<td>pthread_mutex_unlock()</td>
<td>&#x91CA;&#x653E;&#x4E92;&#x65A5;&#x9501;</td>
</tr>
<tr>
<td>pthread_cond_init(...)</td>
<td>&#x521D;&#x59CB;&#x5316;&#x6761;&#x4EF6;&#x5BF9;&#x8C61;</td>
</tr>
<tr>
<td>pthread_cond_destroy(...)</td>
<td>&#x9500;&#x6BC1;&#x6761;&#x4EF6;&#x5BF9;&#x8C61;</td>
</tr>
<tr>
<td>pthread_cond_signal(...)</td>
<td>&#x53D1;&#x51FA;&#x6761;&#x4EF6;&#x4FE1;&#x53F7;&#xFF0C;<br>&#x5524;&#x9192;&#x7B2C;&#x4E00;&#x4E2A;&#x8C03;&#x7528;pthread_cond_wait()&#x800C;&#x8FDB;&#x5165;&#x7761;&#x7720;&#x7684;&#x7EBF;&#x7A0B;</td>
</tr>
<tr>
<td>pthread_cond_wait()</td>
<td>&#x7528;&#x4E8E;&#x7EBF;&#x7A0B;&#x963B;&#x585E;&#x7B49;&#x5F85;&#xFF0C;&#x76F4;&#x5230; pthread_cond_signal &#x53D1;&#x51FA;&#x6761;&#x4EF6;&#x4FE1;&#x53F7;&#x540E;&#x624D;&#x6267;&#x884C;&#x540E;&#x7EED;&#x64CD;&#x4F5C;</td>
</tr>
<tr>
<td>pthread_key_create()</td>
<td>&#x5206;&#x914D;&#x7528;&#x4E8E;&#x6807;&#x8BC6;&#x8FDB;&#x7A0B;&#x4E2D;&#x7EBF;&#x7A0B;&#x7279;&#x5B9A;&#x6570;&#x636E;&#x7684;&#x952E;</td>
</tr>
<tr>
<td>pthread_setspecific()</td>
<td>&#x4E3A;&#x6307;&#x5B9A;&#x7EBF;&#x7A0B;&#x7279;&#x5B9A;&#x6570;&#x636E;&#x952E;&#x8BBE;&#x7F6E;&#x7EBF;&#x7A0B;&#x7279;&#x5B9A;&#x7ED1;&#x5B9A;</td>
</tr>
<tr>
<td>pthread_getspecific()</td>
<td>&#x83B7;&#x53D6;&#x8C03;&#x7528;&#x7EBF;&#x7A0B;&#x7684;&#x952E;&#x7ED1;&#x5B9A;&#xFF0C;&#x5E76;&#x5C06;&#x8BE5;&#x7ED1;&#x5B9A;&#x5B58;&#x50A8;&#x5728; value &#x6307;&#x5411;&#x7684;&#x4F4D;&#x7F6E;&#x4E2D;</td>
</tr>
<tr>
<td>pthread_key_delete()</td>
<td>&#x9500;&#x6BC1;&#x73B0;&#x6709;&#x7EBF;&#x7A0B;&#x7279;&#x5B9A;&#x6570;&#x636E;&#x952E;</td>
</tr>
<tr>
<td>pthread_attr_getschedparam()</td>
<td>&#x83B7;&#x53D6;&#x7EBF;&#x7A0B;&#x4F18;&#x5148;&#x7EA7;</td>
</tr>
<tr>
<td>pthread_attr_setschedparam()</td>
<td>&#x8BBE;&#x7F6E;&#x7EBF;&#x7A0B;&#x4F18;&#x5148;&#x7EA7;</td>
</tr>
<tr>
<td>pthread_equal()</td>
<td>&#x5BF9;&#x4E24;&#x4E2A;&#x7EBF;&#x7A0B;&#x7684;&#x7EBF;&#x7A0B;&#x6807;&#x8BC6;&#x53F7;&#x8FDB;&#x884C;&#x6BD4;&#x8F83;</td>
</tr>
<tr>
<td>pthread_self()</td>
<td>&#x67E5;&#x8BE2;&#x7EBF;&#x7A0B;&#x81EA;&#x8EAB;&#x7EBF;&#x7A0B;&#x6807;&#x8BC6;&#x53F7;</td>
</tr>
<tr>
<td>pthread_cancel()</td>
<td>&#x5728;&#x5B89;&#x5353;NDK&#x4E2D;&#x5DF2;&#x7ECF;&#x88AB;&#x5220;&#x9664;&#x3002;&#x56E0;&#x4E3A;&#x6BD4;&#x8F83;&#x5371;&#x9669;&#x3002;</td>
</tr>
</tbody>
</table>
<h4 id="pthreadcreate"><a name="pthreadcreate" class="anchor-navigation-ex-anchor" href="#pthreadcreate"><i class="fa fa-link" aria-hidden="true"></i></a>pthread_create(...)</h4>
<pre><code class="lang-c">pthread_create(&amp;pthread,<span class="hljs-literal">NULL</span>,threadCallBack,<span class="hljs-literal">NULL</span>);
&#x5176;&#x603B;&#x5171;&#x63A5;&#x6536;<span class="hljs-number">4</span>&#x4E2A;&#x53C2;&#x6570;&#xFF0C;
&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x4E3A;<span class="hljs-keyword">pthread_t</span>&#x5BF9;&#x8C61;&#xFF0C;
&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x4E3A;&#x7EBF;&#x7A0B;&#x7684;&#x4E00;&#x4E9B;&#x5C5E;&#x6027;&#x6211;&#x4EEC;&#x4E00;&#x822C;&#x4F20;<span class="hljs-literal">NULL</span>&#x5C31;&#x884C;&#xFF0C;
&#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x4E3A;&#x7EBF;&#x7A0B;&#x6267;&#x884C;&#x7684;&#x51FD;&#x6570;&#xFF0C;
&#x7B2C;&#x56DB;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x4F20;&#x9012;&#x7ED9;&#x7EBF;&#x7A0B;&#x7684;&#x53C2;&#x6570;
</code></pre>
<p><br></p>
<h4 id="pthreadexit"><a name="pthreadexit" class="anchor-navigation-ex-anchor" href="#pthreadexit"><i class="fa fa-link" aria-hidden="true"></i></a>pthread_exit(...)</h4>
<pre><code class="lang-c">pthread_exit(&amp;thread) ;
&#x53C2;&#x6570;&#x4E5F;&#x53EF;&#x4EE5;&#x4F20;<span class="hljs-literal">NULL</span>&#x3002;
</code></pre>
<h2 id="java&#x4E0E;native&#x5171;&#x4EAB;&#x5185;&#x5B58;"><a name="java&#x4E0E;native&#x5171;&#x4EAB;&#x5185;&#x5B58;" class="anchor-navigation-ex-anchor" href="#java&#x4E0E;native&#x5171;&#x4EAB;&#x5185;&#x5B58;"><i class="fa fa-link" aria-hidden="true"></i></a>1.15. java&#x4E0E;native&#x5171;&#x4EAB;&#x5185;&#x5B58;</h2>
<p>&#x5927;&#x6982;&#x539F;&#x7406;&#xFF0C;&#x5728;native&#x5F00;&#x8F9F;&#x4E00;&#x5757;&#x5185;&#x5B58;&#x3002;&#x5C06;&#x8FD9;&#x5757;&#x5185;&#x5B58;&#x7684;&#x9996;&#x5730;&#x5740;&#x4F20;&#x7ED9;java&#x5C42;&#xFF0C;&#x4EE5;&#x540E;&#x7684;&#x76F8;&#x5173;&#x64CD;&#x4F5C;&#x5C31;&#x901A;&#x8FC7;&#x8FD9;&#x4E2A;&#x5730;&#x5740;&#x83B7;&#x5F97;&#x8FD9;&#x5757;&#x5185;&#x5B58;&#xFF0C;&#x7528;native&#x4EE3;&#x7801;&#x76F4;&#x63A5;&#x64CD;&#x4F5C;&#x5185;&#x5B58;&#x3002;</p>
<pre><code class="lang-xml">&#x6682;&#x65F6;&#x7528;&#x5F97;&#x5C11;&#xFF0C;&#x4EE5;&#x540E;&#x518D;&#x8865;&#x5145;&#x3002;
android&#x4E2D;&#x7684;&#x5E94;&#x7528;&#x6709; Parcel&#xFF0C;&#x56E0;&#x4E3A;&#x76F4;&#x63A5;&#x64CD;&#x4F5C;&#x5185;&#x5B58;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x6BD4;&#x64CD;&#x4F5C;IO&#x7684;Serializable &#x6548;&#x7387;&#x9AD8;&#x3002;
</code></pre>
<h2 id="&#x5176;&#x4ED6;"><a name="&#x5176;&#x4ED6;" class="anchor-navigation-ex-anchor" href="#&#x5176;&#x4ED6;"><i class="fa fa-link" aria-hidden="true"></i></a>1.16. &#x5176;&#x4ED6;</h2>
<pre><code class="lang-xml">RegisterNatives(clazz, methods, size)   // &#x5C06;clazz&#x7C7B;&#x4E2D;&#x7684; &#x6240;&#x6709;&#x65B9;&#x6CD5;methods&#x5168;&#x90E8;&#x6CE8;&#x518C;&#x4E3A;&#x672C;&#x5730;&#x65B9;&#x6CD5;&#x3002;
jlong id= reinterpret_cast<span class="hljs-tag">&lt;<span class="hljs-name">jlong</span>&gt;</span>(record);  // c++ &#x5BF9;&#x8C61;&#x4E0E;&#x5BF9;&#x8C61;&#x53E5;&#x67C4;&#x8FDB;&#x884C;&#x4E92;&#x76F8;&#x8F6C;&#x6362;
auto *record = reinterpret_cast<span class="hljs-tag">&lt;<span class="hljs-name">CameraRecord</span> *&gt;</span>(id);
</code></pre>
<footer class="page-footer"><span class="copyright">&#x65E0;&#x7248;&#x6743; &#x53EF;&#x4EE5;&#x65E0;&#x9650;&#x5236;&#x4F7F;&#x7528;&#xFF01; all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x66F4;&#x65B0;&#x65F6;&#x95F4;&#xFF1A;
2020-08-20 15:19:26
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../QT/QT基础.html" class="navigation navigation-prev " aria-label="Previous page: QT基础">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="JNI基础.html" class="navigation navigation-next " aria-label="Next page: JNI基础">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"JNI","level":"1.6","depth":1,"next":{"title":"JNI基础","level":"1.6.1","depth":2,"path":"chinese/jni/JNI基础.md","ref":"chinese/jni/JNI基础.md","articles":[]},"previous":{"title":"QT基础","level":"1.5.1","depth":2,"path":"chinese/QT/QT基础.md","ref":"chinese/QT/QT基础.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","search-plus","todo","anchor-navigation-ex","copy-code-button","versions-select","fontsettings","sharing","tbfed-pagefooter","donate","local-video","splitter","edit-link","expandable-chapters","favicon","theme-comscore","local-video"],"styles":{"website":"styles/website.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"无版权 可以无限制使用！","modify_label":"该文件更新时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"todo":{},"splitter":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"versions-select":{"type":"branches"},"donate":{"alipay":"https://gitee.com/hnyer/filesOfGitbook/raw/master/files/201803011956_osChina_支付宝收款码.png","alipayText":"支付宝打赏","button":"打赏","title":"","wechat":"https://gitee.com/hnyer/filesOfGitbook/raw/master/files/201803011956_osChina_微信收款码.png","wechatText":"微信打赏"},"fontsettings":{"family":"sans","size":2,"theme":"sepia"},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"favicon":{"shortcut":"assets/images/favicon.ico","bookmark":"assets/images/favicon.ico"},"theme-comscore":{},"local-video":{},"copy-code-button":{},"versions":{"options":[{"value":"https://www.aivin666.cn/java_android/","text":"v1.0"}]},"sharing":{"all":["facebook","google","twitter","weibo","instapaper"],"facebook":false,"google":true,"instapaper":false,"twitter":false,"vk":false,"weibo":true},"edit-link":{"label":"托管页面","base":"https://www.baidu.com/"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{},"search-plus":{}},"theme":"default","author":"Aivin","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Aivin开发笔记","language":"zh-hans","gitbook":"*","description":"Aivin开发笔记"},"file":{"path":"chinese/jni/JNI基础.md","mtime":"2020-08-20T07:19:26.411Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-08-20T09:02:41.305Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-versions-select/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-local-video/video.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

